/*
 * Users.java
 *
 * Created on 12 wrzesie� 2007, 21:43
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package info.mikrotubula.db;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;

/**
 * Entity class Users
 * 
 * @author Krystian
 */
@Entity
@Table(name = "USERS",
    uniqueConstraints=
    @UniqueConstraint(columnNames={"USR_NAME"}))
@NamedQueries( {
        @NamedQuery(name = "Users.findByUsrId", query = "SELECT u FROM Users u WHERE u.usrId = :usrId"),
        @NamedQuery(name = "Users.findByUsrName", query = "SELECT u FROM Users u WHERE u.usrName = :usrName"),
        @NamedQuery(name = "Users.findByUsrPass", query = "SELECT u FROM Users u WHERE u.usrPass = :usrPass"),
        @NamedQuery(name = "Users.findByUsrDate", query = "SELECT u FROM Users u WHERE u.usrDate = :usrDate"),
        @NamedQuery(name = "Users.findByUsrFirstName", query = "SELECT u FROM Users u WHERE u.usrFirstName = :usrFirstName"),
        @NamedQuery(name = "Users.findByUsrLastName", query = "SELECT u FROM Users u WHERE u.usrLastName = :usrLastName"),
        @NamedQuery(name = "Users.findAll", query = "SELECT u FROM Users u"),
        @NamedQuery(name = "Users.findByNameAndPass", query = "SELECT u FROM Users u WHERE u.usrName = :usrName AND u.usrPass = :usrPass"),
        @NamedQuery(name = "Users.search", query = "SELECT u FROM Users u WHERE u.usrName LIKE :searchString OR u.usrFirstName LIKE :searchString OR u.usrLastName LIKE :searchString")
    })
public class Users implements Serializable {

    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name = "USR_ID", nullable = false)
    private Integer usrId;

    @Column(name = "USR_NAME", nullable=false)
    private String usrName;

    @Column(name = "USR_PASS")
    private String usrPass;

    @Column(name = "USR_DATE")
    @Temporal(TemporalType.TIMESTAMP)
    private Date usrDate;

    @Column(name = "USR_FIRST_NAME")
    private String usrFirstName;

    @Column(name = "USR_LAST_NAME")
    private String usrLastName;

    @JoinColumn(name = "USR_PRF_ID", referencedColumnName = "PRF_ID")
    @ManyToOne
    private Profiles profile;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user", fetch = FetchType.LAZY)
    private Collection<Sessions> sessions;

    @OneToMany(mappedBy = "user", fetch=FetchType.LAZY)
    private Collection<Works> works;
    
    @OneToMany(mappedBy = "user", fetch=FetchType.LAZY)
    private Collection<News> news;
    
    @OneToMany(mappedBy = "user", fetch=FetchType.LAZY)
    private Collection<Images> images;
    
    /** Creates a new instance of Users */
    public Users() {
    }

    /**
     * Creates a new instance of Users with the specified values.
     * @param usrId the usrId of the Users
     */
    public Users(Integer usrId) {
        this.usrId = usrId;
    }
    
    public Users(String userName, String userFirstName, String userLastName, String userPassword) {
        this.usrName = userName;
        this.usrFirstName = userFirstName;
        this.usrLastName = userLastName;
        this.usrDate = new Date();
    }

    /**
     * Gets the usrId of this Users.
     * @return the usrId
     */
    public Integer getUsrId() {
        return this.usrId;
    }

    /**
     * Sets the usrId of this Users to the specified value.
     * @param usrId the new usrId
     */
    public void setUsrId(Integer usrId) {
        this.usrId = usrId;
    }

    /**
     * Gets the usrName of this Users.
     * @return the usrName
     */
    public String getUsrName() {
        return this.usrName;
    }

    /**
     * Sets the usrName of this Users to the specified value.
     * @param usrName the new usrName
     */
    public void setUsrName(String usrName) {
        this.usrName = usrName;
    }

    /**
     * Gets the usrPass of this Users.
     * @return the usrPass
     */
    public String getUsrPass() {
        return this.usrPass;
    }

    /**
     * Sets the usrPass of this Users to the specified value.
     * @param usrPass the new usrPass
     */
    public void setUsrPass(String usrPass) {
        this.usrPass = usrPass;
    }

    /**
     * Gets the usrDate of this Users.
     * @return the usrDate
     */
    public Date getUsrDate() {
        return this.usrDate;
    }

    /**
     * Sets the usrDate of this Users to the specified value.
     * @param usrDate the new usrDate
     */
    public void setUsrDate(Date usrDate) {
        this.usrDate = usrDate;
    }

    /**
     * Gets the usrFirstName of this Users.
     * @return the usrFirstName
     */
    public String getUsrFirstName() {
        return this.usrFirstName;
    }

    /**
     * Sets the usrFirstName of this Users to the specified value.
     * @param usrFirstName the new usrFirstName
     */
    public void setUsrFirstName(String usrFirstName) {
        this.usrFirstName = usrFirstName;
    }

    /**
     * Gets the usrLastName of this Users.
     * @return the usrLastName
     */
    public String getUsrLastName() {
        return this.usrLastName;
    }

    /**
     * Sets the usrLastName of this Users to the specified value.
     * @param usrLastName the new usrLastName
     */
    public void setUsrLastName(String usrLastName) {
        this.usrLastName = usrLastName;
    }

    /**
     * Returns a hash code value for the object.  This implementation computes 
     * a hash code value based on the id fields in this object.
     * @return a hash code value for this object.
     */
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (this.usrId != null ? this.usrId.hashCode() : 0);
        return hash;
    }

    /**
     * Determines whether another object is equal to this Users.  The result is 
     * <code>true</code> if and only if the argument is not null and is a Users object that 
     * has the same id field values as this object.
     * @param object the reference object with which to compare
     * @return <code>true</code> if this object is the same as the argument;
     * <code>false</code> otherwise.
     */
    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Users)) {
            return false;
        }
        Users other = (Users)object;
        if (this.usrId != other.usrId && (this.usrId == null || !this.usrId.equals(other.usrId))) return false;
        return true;
    }

    /**
     * Returns a string representation of the object.  This implementation constructs 
     * that representation based on the id fields.
     * @return a string representation of the object.
     */
    @Override
    public String toString() {
        return "info.mikrotubula.db.Users[usrId=" + usrId + "]";
    }

    public Profiles getProfile() {
        return profile;
    }

    public void setProfile(Profiles profile) {
        this.profile = profile;
    }

    public Collection<Sessions> getSessions() {
        return sessions;
    }

    public void setSessions(Collection<Sessions> sessions) {
        this.sessions = sessions;
    }

    public Collection<Works> getWorks() {
        return works;
    }

    public void setWorks(Collection<Works> works) {
        this.works = works;
    }

    public Collection<News> getNews() {
        return news;
    }

    public void setNews(Collection<News> news) {
        this.news = news;
    }

    public Collection<Images> getImages() {
        return images;
    }

    public void setImages(Collection<Images> images) {
        this.images = images;
    }
    
}
